<?php

function getItemHtml($image_height, $image_url, $image_link)
{
    $image_height = $image_height . 'px';
    return "
<li class='item'>
    <a style='height:$image_height;background-image: url($image_url);' target='_blank'  $image_link class='image' ></a>
</li>
    ";
}

function getParam($paramName, $defaultValue)
{
    global $_MODULE;
    $value = $_MODULE[$paramName];
    if (empty($value)) return $defaultValue;
    return $value;
}

function myEcho($paramName, $defaultValue)
{
    echo getParam($paramName, $defaultValue);
}

function getBgAttr()
{
    $bg = '';
    $bg_type = getParam('bg_type', 'color');
    if ($bg_type == 'color') {
        $bg_value = getParam('bg_value', '#63B513');
        $bg = $bg . "background-color:$bg_value;";
    } else {
        $bg_repeat = getParam('repeat_type', 'assets/images/default-thumbnail.png');
        $bg_position = getParam('position_type', 'assets/images/default-thumbnail.png');
        $bg_attachment = getParam('attachment_type', 'assets/images/default-thumbnail.png');
        $bg_image = getParam('bg_value', 'assets/images/default-thumbnail.png');
        $bg = $bg . "background-image: url($bg_image);";
        $bg = $bg . "background-repeat: $bg_repeat;";
        $bg = $bg . "background-position: $bg_position;";
        $bg = $bg . "background-attachment: $bg_attachment;";
    }

    return $bg;
}

function echoLBHtml(){
    $is_show_ring = getParam('is_show_ring', '');

    echo "<div class='container m-sop-slide $is_show_ring'>
        <div class='inner_container'>
            <ol class='slide-pics'>";

    $image_height_array = array();
    $is_empty = true;

    for ($i = 0; $i < getParam('image_num', 2); $i++) {
        $image_url = getParam('image_url_' . $i, '');
        if (empty($image_url)) {
            continue;
        }

        $is_empty = false;
        $image_height = getParam('image_height_' . $i, 400);
        array_push($image_height_array, $image_height);
        echo getItemHtml(
            $image_height,
            $image_url,
            getHref('image_link_' . $i));
    }

    $button_top = $is_empty ? '200px' : (max($image_height_array) / 2) . 'px';
    if ($is_empty) {
        echo getItemHtml(
            '400',
            '../../assets/images/10.jpg',
            'href="#"');
        echo getItemHtml(
            '400',
            'assets/images/9602.jpg',
            'href="#"');
    }

    echo "</ol></div>";

    if (getParam('is_show_arrows', 'show') == 'show') {
        $arrow_type = getParam('arrows_type', '');
        $blue_arrows_next = $arrow_type . '_next';
        $blue_arrows_prev = $arrow_type . '_prev';
        echo "
                    <a style='top:$button_top;' class='prev-btn $blue_arrows_prev'></a>
                    <a style='top:$button_top;' class='next-btn $blue_arrows_next'></a>
                ";
    }

    echo "</div>";
}

function maxThanZero($num){
    return $num < 0 ? 0 : $num;
}

function echoHotHtml(){
    $hot_color = "background-color: yellow;";//删除颜色  $hot_color="";

    $imageNum = getParam('image_num', 2);
    for ($i = 0; $i < $imageNum; $i++) {
        $image_url = getParam('image_url_' . $i, '');
        if (empty($image_url)) {
            continue;
        }

        $hot_html = "";

        $image_height = getParam('image_height_' . $i, 400).'px';

        $hot_params = getParam('hot_params_' . $i, '');
        $hot_links = getParam('hot_links_' . $i, '');

        $z_index = 30;

        if(!empty($hot_params) && !empty($hot_links) ){
            $hot_params = empty($hot_params)?array():explode("|", $hot_params);
            $hot_link_array = empty($hot_links)?array():explode("|", $hot_links);

            $count = count($hot_params);
            for ($j = 0; $j < $count; $j++) {
                $hot_param_array = explode(".",$hot_params[$j]);

                $hot_left = ($hot_param_array[0]+360);

                $hot_top = $hot_param_array[1].'px';
                $hot_width = $hot_param_array[2];
                $hot_height = $hot_param_array[3].'px';
                $hot_link = $hot_link_array[$j];

                if($hot_left + $hot_width > 1560 ){
                    $hot_width = $hot_width - ($hot_left + $hot_width - 1560);
                    $hot_width = maxThanZero($hot_width);
                }else if($hot_left  <  360 ){
                    $hot_width = $hot_width - (360 - $hot_left);
                    $hot_width = maxThanZero($hot_width);
                    $hot_left = 360;
                }


                $hot_width = $hot_width.'px';
                $hot_left = $hot_left.'px';

                $z_index_num = $z_index + $j;

                $hot_html = $hot_html."<a style='
                color: white;
                position: absolute;
                display: block;
                height: $hot_height;
                width: $hot_width;
                z-index: $z_index_num;
                $hot_color
                left:$hot_left;
                top: $hot_top;'
                target='_blank' href='$hot_link'></a>";
            }
        }



        echo
"<div class='hot' style='background-image: url(assets/images/90.jpg);height: $image_height;'>
    <div style='height: 100%;width: 1200px;margin: 0 auto;'>
            $hot_html
    </div>
</div>";
    }
}

function getHot(){

}


?>
<div class="module dshop-um-wl-19-lb module-thirdparty" style='margin-bottom:<? echo getParam('bottom_margin', 0); ?>px;'>
    <div class="bg" style="
            height: <? myEcho('bg_height', '3000') ?>px;<? echo getBgAttr() ?>"></div>

    <?php
        $poster_type = getParam('poster_type','lb');
        if('lb' == $poster_type){
            echoLBHtml();
        }

        if('hot' == $poster_type){
            echoHotHtml();
        }

    ?>

</div>
